<?php

/**
 * 最组合
 */
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

$compose = get_compose();
$response = array('response' => 'compose', 'compose' => $compose);
echo tourldecode($response);

/**
 * 获得最组合的数据
 * @return array{id,name,picture,marketPrice}
 */
function get_compose(){
    $sql = 'SELECT goods_id, goods_name, shop_price, goods_thumb FROM ' . $GLOBALS['ecs']->table('goods') . ' WHERE is_on_sale=1 AND cat_id=101';
    $res = $GLOBALS['db']->getAll($sql);

    $compose= array();

    foreach ($res AS $row)
    {
        if (!empty($row['goods_id']))
        {
            $compose[] = array( 'id' => $row['goods_id'],
            					'name' => urlencode($row['goods_name']),
                                'picture'  => $_SERVER['HTTP_HOST'] . '/' . $row['goods_thumb'],    //拼接成url
                                'marketPrice' => $row['shop_price']);
        }
    }
    return $compose;
}
?>